package com.netjava.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.netjava.form.AddMessageForm;
import com.netjava.pojo.Message;
import com.netjava.service.IMessageService;
import com.netjava.service.IUserService;

public class MessageAction extends BaseAction {
	public ActionForward add(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ActionForward forward=mapping.getInputForward();
		AddMessageForm addMessageForm = (AddMessageForm) form;
		String authcode=(String) request.getSession().getAttribute("userInfo.authcode");
		String code=request.getParameter("valCode");
		Message message=addMessageForm.getMessage();
		//检查验证码是否正确
		if(authcode.equals(code)){
			IMessageService messageService=(IMessageService)getBean("messageService");
			messageService.add(message);
			

			System.out.println("保存成功！");
			
			forward=mapping.findForward("success");//留言成功时返回的页面
		}
		else{
			request.setAttribute("msg", "验证码错误请重新输入！");
			forward=mapping.findForward("validate");//注册成功时返回的页面
		}
		
		
		System.out.println("保存成功！");
		
		
		return forward;
	}

}
